package com.xyht.sca_s.student_manage_system.modules.assetFixedSelfInspection.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedSelfInspection.entity.req.SmsAssetSelfInspectionPlanReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedSelfInspection.service.SmsAssetSelfInspectionPlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 资产自查计划表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-28
 */
@RestController
@RequestMapping("/assetFixedSelfInspection/plan")
@SecretBody
public class SmsAssetSelfInspectionPlanController {

    @Resource
    private SmsAssetSelfInspectionPlanService smsAssetSelfInspectionPlanService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加资产自查计划")
    @PostMapping("/add")
    public ResponseResult addPlan(@RequestBody SmsAssetSelfInspectionPlanReq planReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetSelfInspectionPlanService.addPlan(planReq, userId);
    }

    @ApiOperation("修改资产自查计划")
    @PostMapping("/update")
    public ResponseResult updatePlan(@RequestBody SmsAssetSelfInspectionPlanReq planReq) {
        return smsAssetSelfInspectionPlanService.updatePlan(planReq);
    }

    @ApiOperation("删除资产自查计划")
    @PostMapping("/deleted")
    public ResponseResult deletedPlan(@RequestBody SmsAssetSelfInspectionPlanReq planReq) {
        return smsAssetSelfInspectionPlanService.deletedPlan(planReq);
    }

    @ApiOperation("获取资产自查计划详情")
    @GetMapping("/detail")
    public ResponseResult getPlanDetail(@RequestParam(value = "id")String id) {
        return smsAssetSelfInspectionPlanService.getPlanDetail(id);
    }

    @ApiOperation("获取资产自查计划列表")
    @GetMapping("/list")
    public ResponseResult getPlanList(@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "planName",required = false)String planName,
                                      @RequestParam(value = "isUse",required = false) Integer isUse) {
        return smsAssetSelfInspectionPlanService.getPlanList(pageSize, pageNum, planName, isUse);
    }

    @ApiOperation("资产自查计划启用/关闭")
    @PostMapping("/isOpen")
    public ResponseResult isOpen(@RequestBody SmsAssetSelfInspectionPlanReq planReq) {
        return smsAssetSelfInspectionPlanService.isOpen(planReq);
    }

}

